﻿using Base.Runtime;
using Extension.Runtime;
using UnityEngine;
using UnityEngine.UI;

namespace UIModule
{
    public class UILayerInfo:XObject
    {
        public Transform CachedTransform{ get; private set; }
        public Canvas LayerCanvas { get; private set; }
        public CanvasGroup LayerGroup{ get; private set; }
        public string LayerName { get; private set; }
        
        public RectTransform RectTransform { get; private set; }
        
        public GraphicRaycaster Raycaster { get; private set; }    

        public UILayerInfo(string layerName,Canvas uiRoot)
        {
            LayerName = layerName;
            LayerCanvas = new GameObject(layerName).AddComponent<Canvas>();
            LayerCanvas.transform.SetParent(uiRoot.transform);
            
            RectTransform = LayerCanvas.GetComponent<RectTransform>();
            RectTransform.Reset();
            RectTransform.SetRectFullScreen();
            
            LayerCanvas.overrideSorting = true;
            
            LayerGroup = LayerCanvas.gameObject.AddComponent<CanvasGroup>();
            Raycaster = LayerCanvas.gameObject.AddComponent<GraphicRaycaster>();
            
            LayerGroup.alpha = 1;
            LayerGroup.interactable = true;
            LayerGroup.blocksRaycasts = true;
            CachedTransform = LayerCanvas.transform;
        }

        protected override void OnDispose()
        {
            
        }
    }
}